<?php
// $Id$

include_once('BaseModel.class.php');

class ManagePrivilegeModel extends BaseModel
{
    function collect($offset=null,$limit=null,$search=array(),$by='1',$sort='')
	{
		$where = ($search) ? "WHERE LOWER({$search['searchfield']}) LIKE '%{$search['searchtext']}%'" : "WHERE 1";

		if (is_null($offset)) {
	        $query = "SELECT COUNT(*) FROM usertype $where";
		} else {
	        $query = "SELECT * FROM usertype $where ORDER BY $by $sort LIMIT $offset,$limit";
		}
		return $this->query($query, true);
    }

    function detail ($id)
    {
        $query = "SELECT * FROM usertype WHERE id='$id'";
        return $this->query($query, true);
    }

    /*
     * Add usertype and return the new usertype_id
     *
     */
    function ins($detail)
    {
        return $this->insert('usertype', $detail);
        return $this->last_insert_id('usertype');
    }

    /*
     * Update usertype for a particular usertype_id
     *
     */
    function edit ($id, $detail)
    {
        return $this->update('usertype', $detail, "id = '$id'");
    }	

    /*
     * Delete Privilege detail for a particular usertype_id
     *
     */
    function deactivate ($id)
    {
        $query = "UPDATE usertype SET active = '0' WHERE id='$id'";
        return $this->query($query, false);
    }
    function activate ($id)
    {
        $query = "UPDATE usertype SET active = '1' WHERE id='$id'";
        return $this->query($query, false);
    }
}

?>
